// pages/mode/mode.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tableList: [],
    result: [],
    num: 0,
    time: 2 * 60 * 1000,
    timer: 2,
    textTime:'',
    bfb: 0
  },

  timers() {
    // this.setData({
    //   timer: this.data.timer * 60
    // })
    let oldTime = this.data.timer * 60
    let newtimers = oldTime;
    let newtimer = setInterval(() => {
      let hours = Math.floor(newtimers / 3600);
      let min = Math.floor(newtimers / 60);
      let s = newtimers % 60;
      newtimers--;
      this.setData({
        timer:newtimers,
        textTime:this.fill0(hours) + ":" + this.fill0(min) + ":" + this.fill0(s),
        bfb:Math.floor(newtimers/oldTime*100)
      })
      // console.log(s)
      // console.log(hours + ":" + min + ":" + s)
    },1000)

  },

  fill0(val){
    return val<10?'0'+val:val
  },

  onChange(event) {
    console.log(event.detail)
    this.setData({
      result: event.detail,
    });
  },

  nextt() {
    if (this.data.num < this.data.tableList.length - 1) {
      this.setData({
        num: this.data.num += 1
      })
    }
    // console.log(this.data.num,this.data.tableList.length-1)
  },

  restore() {
    if (this.data.num > 0) {
      this.setData({
        num: this.data.num -= 1
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.timers()
    // console.log(options)
    wx.request({
      url: 'http://localhost:3001/questions/randList',
      data: {},
      header: {},
      success: (res) => {
        // console.log(res.data.data)
        let resData = res.data.data;
        resData.forEach(item => {
          item.options = JSON.parse(item.options)
          // console.log(item.options)
        })
        this.setData({
          tableList: resData
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})